/**
  ******************************************************************************
  * @file    Libraries/Device/TS32F020D/TS32F020D_LL_Driver/src/ts32f020d_ll_sysctrl.c
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the SYSCTRL LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "include.h"

/** @addtogroup TS32F020D_StdPeriph_Driver TS32F020D Driver
  * @{
  */
  
/** @defgroup sysctrl_interface_gr SYSCTRL Driver
  * @ingroup  TS32F020D_StdPeriph_Driver
  * @{
  */

/** @addtogroup SYSCTRL_LL_Driver SYSCTRL LL Driver
  * @ingroup  sysctrl_interface_gr
  * @{
  */
  
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup SYSCTRL_LL_Inti_Cfg SYSCTRL LL Initialization And Configuration
  * @ingroup  SYSCTRL_LL_Driver
  * @brief    SYSCTRL LL Initialization And Configuration
  * @{
  */

/**
  * @brief  Enable the selected gpio port debounce.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_Pin_x where x can be (0..15).
  * @retval None.
  */
void ll_sysctrl_gpio_port_deb_en(GPIO_TypeDef* p_gpio, u16 gpio_pin)
{ 
    if(p_gpio==GPIOA)
    {
        SYSCTRL->SYS_CON2 |= gpio_pin;
    }
    else if(p_gpio==GPIOB)
    {
        SYSCTRL->SYS_CON2 |= gpio_pin << 16;
    }
}

/**
  * @brief  Disable the selected gpio port debounce.
  * @param  p_gpio: where x can be (A..C) to select the GPIO peripheral.
  * @param  gpio_pin: specifies the port bits to be written.
  *   This parameter can be any combination of LL_GPIO_Pin_x where x can be (0..15).
  * @retval None.
  */
void ll_sysctrl_gpio_port_deb_dis(GPIO_TypeDef* p_gpio, u16 gpio_pin)
{
    if(p_gpio==GPIOA)
    {
        SYSCTRL->SYS_CON2 &= ~gpio_pin;
    }
    else if(p_gpio==GPIOB)
    {
        SYSCTRL->SYS_CON2 &= ~(gpio_pin << 16);
    }
}

/**
  * @brief  Enable monitor which wake up group and Choose which edge to monitor.
  * @param  wkup_group: choose which wake up group to monitor. 
  *   This parameter can be any combination of LL_SYSCTRL_WKUP_x where x can be (0..11).
  * @param  wkup_edge: choose which edge to monitor.
  *   This parameter can be selected as LL_SYSCTRL_WKUP_RISING or LL_SYSCTRL_WKUP_FALLING.
  * @retval None.
  */
void ll_sysctrl_wkup_en_edge_sel(TYPE_ENUM_LL_WKUP wkup_group, TYPE_ENUM_LL_WKUP_EDGE wkup_edge)
{
    if(!wkup_edge)
        SYSCTRL->WKUP_CON0 = (SYSCTRL->WKUP_CON0) & ~LL_SYSCTRL_WKUP_CON0_WKUP_EDGE_CHOOSE(wkup_group);
    else
        SYSCTRL->WKUP_CON0 = (SYSCTRL->WKUP_CON0) | LL_SYSCTRL_WKUP_CON0_WKUP_EDGE_CHOOSE(wkup_group);
    
    SYSCTRL->WKUP_CON0 |= LL_SYSCTRL_WKUP_CON0_WKUP_EN(wkup_group);
}


/**
  * @brief swd disable 
  * @param None  
  * @note  if need using SWD pin as gpio, you need call this function to disable swd
  * @retval None  
  */
void swd_disable(void)
{
    SYSCTRL_REG_OPT(SYSCTRL->SYS_CON1 &= ~LL_SYSCTRL_CON1_SWD_EN); 
}

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
